<?php

session_start();

$video_id = $_GET['video_id'];
$thisAuthor = $_GET['thisAuthor'];

include('../../../sidebardbinfo-live.php');

// connect to the database
$tagslink = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$tagslink) {
	die('Problem connecting to database server : ' . mysql_error());
}

// make $dbname the current db
$tagsdb_selected = mysql_select_db($dbname, $tagslink);
if (!$tagsdb_selected) {
	die ('Problem connecting to database : ' . mysql_error());
}

$tagsstmt = "SELECT k.word FROM tags_lookup l JOIN tags_keywords k ON (l.word_id=k.word_id) WHERE l.video_id='".$video_id."'";

$tagsres = mysql_query($tagsstmt);
if (!$tagsres) {
	die ('Problem with query : ' . mysql_error());
}

$tags = "";

// no tags
if (mysql_num_rows($tagsres)>0) {
	$counter = 0;
	while ($currenttags = mysql_fetch_assoc($tagsres)) {
		$counter++;
		if ($thisAuthor == $_SESSION['seesmicName']) {
		    $tags .= "<a href=\"javascript:showTagVideos('".$currenttags["word"]."',1)\">".stripslashes($currenttags["word"])."</a>";
			$tags .= "<a href=\"javascript:removeTag('".$video_id."','".$currenttags["word"]."','".$thisAuthor."')\"><img src='images/delete.gif' width='16' height='16' hspace='0' vspace='0' border='0' alt='remove this tag' /></a> ";
		} else {
			if ($counter>1) {
				$tags .= ", ";
			}
		    $tags .= "<a href=\"javascript:showTagVideos('".$currenttags["word"]."',1)\">".stripslashes($currenttags["word"])."</a>";
		}
	}
} else {
	$tags = "this video has no tags";
}

if ($thisAuthor == $_SESSION['seesmicName']) {
	echo "\n<form onSubmit='return false;'>";
	echo "\n\t<input name='tagInput' id='tagInput' size='10' maxlength='25' />";
	echo "\n\t<input type='button' onclick=\"javascript:addTag('".$video_id."',document.getElementById('tagInput').value,'".$thisAuthor."');\" value='add a tag' />";
	echo "\n</form>";
}
echo "\n".$tags."\n";

mysql_close($tagslink);
?>